package com.xtpt.disaster.service.impl;


import com.xtpt.disaster.bean.NodeInfo;
import com.xtpt.disaster.mapper.NodeInfoMapper;
import com.xtpt.disaster.service.NodeInfoManageService;
import com.xtpt.disaster.utils.IDGenerator;
import com.xtpt.disaster.utils.LongIDUtiles;
import com.xtpt.disaster.utils.TimeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NodeManageServiceImpl implements NodeInfoManageService {
    @Autowired
    NodeInfoMapper nodeInfoMapper;

    @Override
    public int insertNodeInfo(NodeInfo nodeInfo) {
        Long id = LongIDUtiles.getLongId();
        Date createTime = TimeUtil.dateMaker();
        Date updateTime = TimeUtil.dateMaker();
        nodeInfo.setNodeId(id);
        nodeInfo.setCreateTime(createTime);
        nodeInfo.setUpdateTime(updateTime);
        return nodeInfoMapper.insert(nodeInfo);
    }

    @Override
    public int insertNodeInfoSelective(NodeInfo nodeInfo) {
        Long id = IDGenerator.longid();
        Date createTime = TimeUtil.dateMaker();
        Date updateTime = TimeUtil.dateMaker();
        nodeInfo.setNodeId(id);
        nodeInfo.setCreateTime(createTime);
        nodeInfo.setUpdateTime(updateTime);
        return nodeInfoMapper.insertSelective(nodeInfo);
    }

    @Override
    public NodeInfo selectById(Long id) {
        return nodeInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<NodeInfo> selectByIp(String ip) {
        return nodeInfoMapper.selectByIp(ip);
    }

    @Override
    public List<NodeInfo> selectAll() {
        return nodeInfoMapper.selectAll();
    }

    @Override
    public int updateById(NodeInfo nodeInfo) {
        Date updatetime = TimeUtil.dateMaker();
        nodeInfo.setUpdateTime(updatetime);
        return nodeInfoMapper.updateByPrimaryKey(nodeInfo);
    }

    @Override
    public int updateByIdSelective(NodeInfo nodeInfo) {
        Date updatetime = TimeUtil.dateMaker();
        nodeInfo.setUpdateTime(updatetime);
        return nodeInfoMapper.updateByPrimaryKeySelective(nodeInfo);
    }

    @Override
    public int deleteById(Long id) {
        return nodeInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteBatch(long[] nodeIdList) {
        return nodeInfoMapper.deleteBatch(nodeIdList);
    }

}
